﻿@inject IStringLocalizer<DropdownItems> Localizer

<div class="row">
    <div class="col-12 col-sm-6">
        <Dropdown TValue="string" Items="@Foos">
        </Dropdown>
    </div>
    <div class="col-12 col-sm-6">
        <Button @onclick="@AddItem">@Localizer["AddItem"]</Button>
        <Button @onclick="@RemoveItem" Color="Color.Danger">@Localizer["RemoveItem"]</Button>
    </div>
</div>

@code {
    private List<SelectedItem> Foos { get; set; } = new List<SelectedItem>();

    /// <summary>
    /// AddItem
    /// </summary>
    private void AddItem()
    {
        Foos.Add(new SelectedItem($"{Foos.Count}", $"{Localizer["City"]} {Foos.Count}"));
    }

    /// <summary>
    /// RemoveItem
    /// </summary>
    private void RemoveItem()
    {
        if (Foos.Any())
        {
            Foos.RemoveAt(0);
        }
    }

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Foos = new List<SelectedItem>
        {
            new SelectedItem{ Text=Localizer["Item1"], Value="0"},
            new SelectedItem{ Text=Localizer["Item2"], Value="1"},
            new SelectedItem{ Text=Localizer["Item3"], Value="2"},
        };
    }
}
